package vbox;

use warnings;

our $VERSION = '1.00';

use base 'Exporter';

our @EXPORT = qw(vbox_list_vms vbox_list_hdds);

sub vbox_list_vms() {
	my %res;
	my $out;
	$out = qx(vboxmanage list vms);
	foreach my $line (split(/\n/, $out)){
		if ($line =~ /"(.+)"\s+{(.+)}/){
			$res{$2}{name} = $1;
			$res{$2}{running} = 0;
		}
		
	}
	$out = qx(vboxmanage list runningvms);
	foreach my $line (split(/\n/, $out)){
		if ($line =~ /"(.+)"\s+{(.+)}/){
			$res{$2}{name} = $1;
			$res{$2}{running} = 1;
		}
		
	}
	return %res;
}

sub vbox_list_hdds() {
	my %res;
	my $out;
	$out = qx(vboxmanage list hdds);
	foreach my $line (split(/\n/, $out)){
		if ($line =~ /^UUID:\s+([a-z0-9\-]+)/){
			$res{$1} = 1;
		}
	}
	return %res;
}

1;
